import { FrameworkLifeCycles } from '../interfaces';
const rawPublicPath = window.__INJECTED_PUBLIC_PATH_BY_QIANKUN__;
export default function getAddOn(global, publicPath = '/') {
  let hasMountedOnce = false;
  return {
    async beforeLoad() {
      global.__INJECTED_PUBLIC_PATH_BY_QIANKUN__ = publicPath;
    },

    async beforeMount() {
      if (hasMountedOnce) {
        global.__INJECTED_PUBLIC_PATH_BY_QIANKUN__ = publicPath;
      }
    },

    async beforeUnmount() {
      if (rawPublicPath === undefined) {
        delete global.__INJECTED_PUBLIC_PATH_BY_QIANKUN__;
      } else {
        global.__INJECTED_PUBLIC_PATH_BY_QIANKUN__ = rawPublicPath;
      }

      hasMountedOnce = true;
    }

  };
}